home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / PRIVATE.ZIP / _BACKCHR.C < prev    next >
Text File  |  1992-11-21  |  3KB  |  102 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3.  
  4. #ifndef NDEBUG
  5. char *rcsid__backchr = "$Header: c:/curses/private/RCS/_backchr.c%v 2.0 1992/11/15 03:24:15 MH Rel $";
  6. #endif
  7.  
  8.  
  9.  
  10.  
  11. /*man-start*********************************************************************
  12.  
  13.   PDC_backchar()       - Visually erase character in window
  14.  
  15.   PDCurses Description:
  16.        This is a private PDCurses function
  17.  
  18.        This routine will visually erase a character.  It is called by
  19.        the PDCurses character I/O routines.
  20.  
  21.   PDCurses Return Value:
  22.        This routine will return OK upon success and otherwise ERR will be
  23.        returned.
  24.  
  25.   PDCurses Errors:
  26.        It is an error to pass a NULL WINDOW pointer.
  27.  
  28.   Portability:
  29.        PDCurses        int     PDC_backchar( WINDOW* w, char* ch, int* len );
  30.  
  31. **man-end**********************************************************************/
  32.  
  33. int    PDC_backchar(WINDOW *w, char *ch, int *len)
  34. {
  35.        int     nbs = 0;
  36.        int     x = w->_curx;
  37.        int     ts = w->_tabsize;
  38.        chtype* s = &w->_y[w->_cury][x - 1];
  39.        char*   p = c_strbeg;
  40.        bool    save_raw_out = _cursvar.raw_out;
  41.  
  42.  
  43.        if (w == (WINDOW *)NULL)
  44.                return( ERR );
  45.  
  46.        (*len)--;               /* Now we are zero relative */
  47.        (*len)--;               /* Now we are looking at the previous
  48.                                 * character */
  49.        nbs++;
  50.        /*
  51.         * Determine number of characters to erase...
  52.         */
  53.        if ((ch[*len] < ' ') || (*s == 0x7f))   /* ctrl-char has size 2  */
  54.        {
  55.                nbs++;
  56.                (*len)--;
  57.        }
  58.  
  59.        if (ch[*len] == '\t')   /* tabs are very special */
  60.        {
  61.                for (; p < ch; p++)
  62.                {
  63.                        if (*p == '\t')
  64.                                x = ((x / ts) + 1) * ts;
  65.                        else
  66.                        {
  67.                                if ((*p < ' ') || (*p == 0x7f))
  68.                                        x += 2;
  69.                                else
  70.                                        x++;
  71.                        }
  72.                        if (x >= w->_maxx)      /* go to next line? */
  73.                                x = 0;
  74.                }
  75.                if (!(w->_curx))
  76.                        nbs = w->_maxx - x;
  77.                else
  78.                        nbs = w->_curx - x;
  79.        }
  80.        /*
  81.         * Erase the characters and update...
  82.         */
  83.        _cursvar.raw_out = FALSE;  /* ensure backspace handled in xlat mode */
  84.        while (nbs--)
  85.        {
  86.                if (w->_curx > 0)
  87.                {
  88.                        waddstr(w, "\b \b");
  89.                }
  90.                else
  91.                if (w->_cury)
  92.                {
  93.                        mvwaddch(w, w->_cury - 1, w->_maxx - 1, ' ');
  94.                        wmove(w, w->_cury - 1, w->_maxx - 1);
  95.                }
  96.        }
  97.        ch[*len] = '\0';
  98.        _cursvar.raw_out = save_raw_out;
  99.        wrefresh(w);
  100.        return( OK );
  101. }
  102.